package cn.htsyb.synergy.tester.frame;

import cn.htsyb.synergy.tester.exception.AssertException;
import com.jayway.jsonpath.JsonPath;

import java.util.List;

public class JsonAssert {

    public boolean AssertArrayLength(String jsonPath, String jsonStr, String wishVal) {
        List<Object> numList = JsonPath.parse(jsonStr).read(jsonPath);
        boolean bool = false;
        for (Object object : numList) {
            String length = object.toString();
            if (!wishVal.equals(length)) {
                new AssertException("目标值" + length + "与期望值" + wishVal + "不匹配");
            }
            bool = true;
        }
        return bool;
    }

    public boolean AssertStringValue(String jsonPath, String jsonStr, String wishVal) {
        List<Object> numList = JsonPath.parse(jsonStr).read(jsonPath);
        boolean bool = false;
        for (Object object : numList) {
            String length = object.toString();
            if (!wishVal.equals(length)) {
                new AssertException("目标值" + length + "与期望值" + wishVal + "不匹配");
            }
            bool = true;
        }
        return bool;
    }

}
